package com.dv.driverless.service.impl;

import com.dv.common.exception.ServiceException;
import com.dv.driverless.domain.BasicDepartment;
import com.dv.driverless.mapper.BasicDepartmentMapper;
import com.dv.driverless.mapper.BasicDriverMapper;
import com.dv.driverless.mapper.BasicVehicleMapper;
import com.dv.driverless.service.IBasicDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 运输单位信息Service业务层处理
 *
 * @author ruoyi
 * @date 2023-04-06
 */
@Service
public class BasicDepartmentServiceImpl implements IBasicDepartmentService
{
    @Autowired
    private BasicDepartmentMapper basicDepartmentMapper;

    @Autowired
    private BasicVehicleMapper basicVehicleMapper;

    @Autowired
    private BasicDriverMapper basicDriverMapper;

    /**
     * 查询运输单位信息
     *
     * @param id 运输单位信息主键
     * @return 运输单位信息
     */
    @Override
    public BasicDepartment selectBasicDepartmentById(Long id)
    {
        return basicDepartmentMapper.selectBasicDepartmentById(id);
    }

    /**
     * 查询运输单位信息列表
     *
     * @param basicDepartment 运输单位信息
     * @return 运输单位信息
     */
    @Override
    public List<BasicDepartment> selectBasicDepartmentList(BasicDepartment basicDepartment)
    {
        return basicDepartmentMapper.selectBasicDepartmentList(basicDepartment);
    }

    /**
     * 新增运输单位信息
     *
     * @param basicDepartment 运输单位信息
     * @return 结果
     */
    @Override
    public int insertBasicDepartment(BasicDepartment basicDepartment)
    {
        return basicDepartmentMapper.insertBasicDepartment(basicDepartment);
    }

    /**
     * 修改运输单位信息
     *
     * @param basicDepartment 运输单位信息
     * @return 结果
     */
    @Override
    public int updateBasicDepartment(BasicDepartment basicDepartment)
    {
        return basicDepartmentMapper.updateBasicDepartment(basicDepartment);
    }

    /**
     * 批量删除运输单位信息
     *
     * @param ids 需要删除的运输单位信息主键
     * @return 结果
     */
    @Override
    public int deleteBasicDepartmentByIds(Long[] ids)
    {
        if (basicDriverMapper.selectBasicDriverByDepartmentIds(ids)>0 || basicVehicleMapper.selectBasicVehicleByDepartmentIds(ids)>0){
            throw new ServiceException("部门已分配,删除失败！");
        }
        return basicDepartmentMapper.deleteBasicDepartmentByIds(ids);
    }

    /**
     * 删除运输单位信息信息
     *
     * @param id 运输单位信息主键
     * @return 结果
     */
    @Override
    public int deleteBasicDepartmentById(Long id)
    {
        return basicDepartmentMapper.deleteBasicDepartmentById(id);
    }

}
